package com.example.demo;

import java.util.UUID;

public class TestSynchronized {

    public static void main(String[] args) {
        String[] strings ={"ab","bc","cd","de","ef","fg","gh","hi","ab","bc"};
        Calcu calcu = new Calcu();
        for(int i = 0;i<10;i++){
            final int k = i;
            new Thread(new Runnable() {
                @Override
                public void run() {
                    calcu.add(strings[k],k);
                }
            },"thread_"+i).start();
        }
    }
}

class Calcu {

    public void add(String instanceId,int i){
        synchronized (instanceId){
            System.out.println("Thread:"+Thread.currentThread().getName());
            System.out.println("=======instanceId:"+instanceId+",i="+i+"===========");
        }
    }
}